
package test.jackys_one;

import android.app.Activity;
import android.app.AlertDialog;
//import android.app.Dialog;
import android.os.Bundle;
import android.widget.Button;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
//import android.view.View.OnClickListener;
//import android.app.AlertDialog;
import android.content.DialogInterface; 
import android.content.Intent;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Random;
import android.view.LayoutInflater;



public class menu1 extends Activity {
		
		private Random m_rand = new Random();
		int max=100;
		int realnum;
	
		int tempnum=0;
		
		
		Button result;
		Button btnClose;
		TextView resultText;
		EditText inputText;
		
		


	    public void onCreate(Bundle savedInstanceState) {
	    	setTheme(android.R.style.Theme_NoTitleBar);
	    	super.onCreate(savedInstanceState);
	      
	    	
	    	startgame();

	    	
	    	
	    //	startgame();
	    }
	    
	    	
	    
	    
	    
	    private void startgame()
	    {
	    	
	    	

	    	realnum=m_rand.nextInt(max+1);
	    	
	    	setContentView(R.layout.menu1);
		      
	         
        	result=(Button)findViewById(R.id.menu1_result);
        	btnClose=(Button)findViewById(R.id.backtomain);
        	inputText=(EditText)findViewById(R.id.EditText01);
        	//inputText.setInputType(0); // Is is reload then keyboard will be hide.
        	inputText.setHint("1~100占싼딆뵠");
        	
			resultText=(TextView)findViewById(R.id.textview01);
			
			
        	result.setOnClickListener(new Button.OnClickListener(){
              		public void onClick(View v) {
        			
              			String temp=inputText.getText().toString();
              			
              			if(temp==null||"".equals(temp)) { 
              				Toast toast = Toast.makeText(menu1.this,"占썬꺃�꾤몴占쏙옙�낆젾占쏙옙",Toast.LENGTH_SHORT);
              				toast.setGravity(Gravity.TOP, 8, 20);
              				toast.show();
              				
              			} // edittext�⑤벉媛싷㎗�롡봺 
              		
              			
              			else {
          				tempnum=Integer.parseInt(temp);
          				if(tempnum<1||tempnum>max)
          				{
          					Toast toast2 = Toast.makeText(menu1.this,"�띯뫂六쏙옙占�",Toast.LENGTH_LONG);
              				toast2.setGravity(Gravity.TOP, 8, 20);
              				toast2.show();
              				inputText.setHint("1 to 100");
              				inputText.setText("");
              				
          					
          				}
          				
          				else
          				{
          				
          					if(realnum==tempnum) {
          						resultText.setText("占쎈베�잞옙�낅빍占쏙옙"+temp+" "+realnum);
          						goAlert2();
          					}
          					
          					else if(realnum>tempnum) {
    	        			
          						
          					resultText.setText("        "+temp+" < ???");
    	        			inputText.setHint("占썬끉��");
    	        			inputText.setText("");
    	        			
    	        			LayoutInflater inflater	= getLayoutInflater();
          					View layout = inflater.inflate(R.layout.toastshowup,(ViewGroup)findViewById(R.id.toast_up_show));
          					ImageView image=(ImageView)layout.findViewById(R.id.toast_up);
          					
          					image.setImageResource(R.drawable.toast_up);
          					Toast toastupimage = new Toast(getApplicationContext()); 
          					toastupimage.setGravity(Gravity.TOP, 0, 70);
          					toastupimage.setDuration(Toast.LENGTH_SHORT);
          					toastupimage.setView(layout);
          					toastupimage.show();
    	        			}
    	        									
    	        			else {
    	        			resultText.setText("        "+temp+" > ???"); 
    	        					/* resultText.setText("DOWN!\n"+temp+" > ??? _"+realnum) */
    	        			inputText.setHint("占썬끉��");
    	        			inputText.setText("");
    	        			
    	        			LayoutInflater inflater2 = getLayoutInflater();
          					View layout = inflater2.inflate(R.layout.toastshowdown,(ViewGroup)findViewById(R.id.toast_down_show));
          					ImageView image=(ImageView)layout.findViewById(R.id.toast_down);
          					
          					image.setImageResource(R.drawable.toast_down);
          					Toast toastdownimage = new Toast(getApplicationContext()); 
          					toastdownimage.setGravity(Gravity.TOP, 0, 70);
          					toastdownimage.setDuration(Toast.LENGTH_SHORT);
          					toastdownimage.setView(layout);
          					toastdownimage.show();
    	        			}
    	        		
              			
              				}
              	
              			}
        	}
        	});
        
        
        
        	
    //�ル굝利븃린袁る뱣    	
        btnClose.setOnClickListener(new Button.OnClickListener(){
           	public void onClick(View v) {
        	goAlert1(); // 占쎌빘毓�筌ｌ꼶��占썩뫁��

        	}	        	
       });
        
	
	    
	    }
	    
	    
	    private void goAlert1(){
	    AlertDialog.Builder alert = new AlertDialog.Builder(menu1.this);
	    
	    alert.setTitle("Back To Main");
	    alert.setMessage("Would you go back to the main screen?");
	    //alert.setIcon(R.drawabe.�곕떽占쏙옙醫됱쒀);
	    alert.setCancelable(false);
	    
	    alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
			//	inputText.setInputType(0);
				dialog.dismiss(); // dialog 占싼됱뵬筌욑옙
				finish();
				
				
				
	    	}
	    });
	    
	    alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.cancel(); // dialog 占싼됱뵬筌욑옙
	    	}
	    });
	    
	   alert.show(); 	
	    } // end of goAlert1()
	    
	    
	    
	    private void goAlert2(){
		    AlertDialog.Builder alert = new AlertDialog.Builder(menu1.this);
		    
		    alert.setTitle("Congratulation!");
		    alert.setMessage("占쎈베�잞옙占쏙옙醫롳옙 �믩��졿�占�\nRe Game?");
		    //alert.setIcon(R.drawabe.�곕떽占쏙옙醫됱쒀);
		    alert.setCancelable(false);
		    
		    alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.cancel(); // dialog 占싼됱뵬筌욑옙
				
					startgame();
					
				}
		    });
		    
		    alert.setNegativeButton("No. Go To main", new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					
					dialog.dismiss(); // dialog 占싼됱뵬筌욑옙
					finish();
		    	}
		    });
		    
		   alert.show(); 	
		    } // end of goAlert1()
	    
	} //end of class

